#/usr/bin/env python
# -*- coding: utf8 -*-
# title       :
# description :
# author      :'ShenMeng'

import maya.cmds as cmds
import maya.mel as mel

class Validation(object):
    name = u'EmptyLayer | 空层检查'
    dataDict = dict()

    def execute(self):
        self.dataDict = {}
        layerTypeDict = {'displayLayer':cmds.editDisplayLayerMembers}#, 'renderLayer':cmds.editRenderLayerMembers}
        for layerType, command in layerTypeDict.iteritems():
            for layer in cmds.ls(type=layerType):
                if cmds.getAttr(layer + ".identification"):
                    layerContents = layerTypeDict[layerType](layer, q=1)
                    if not layerContents:
                        if self.dataDict.get(layerType, False):
                            self.dataDict[layerType].append(layer)
                        else:
                            self.dataDict[layerType] = [layer]
        return self.dataDict

    def correct(self):
        for type, layerList in self.dataDict.iteritems():
            for layer in layerList:
                mel.eval('deleteIfNotReferenced("' + layer + '")')

    def search(self, obj):
        status = '0'
        for layer in self.dataDict[obj]:
            if status == '0':
                mel.eval('layerEditorLayerButtonSelect ' + status +' ' + layer)
                status = '4'
            else:
                mel.eval('layerEditorLayerButtonSelect ' + status + ' ' + layer)

